Geo maps
The GeoMap control draws a map from a GeoJSON file: every feature of the
file is a land (a country, a state, a region) drawn as a vector shape. A world map is built in. A HeatLandSeries
gives a value to some of the lands and paints each one with a color taken from a gradient, the result is a
choropleth map.
This article highlights the most used features. Every property is listed in the API explorer:
GeoMap,
HeatLandSeries and
GeoMapChart (the CoreChart of the control).
There is no XAML version of HeatLandSeries: create the series in code and bind the Series property. Declare the
title as XamlDrawnLabelVisual.
Basic map
Add a HeatLandSeries to the Series of the map and fill its Lands with HeatLand items. The Name of a
HeatLand is the short name of a land in the map, and its Value sets the color of that land. In the built-in world
map the short names are the ISO 3166-1 alpha-3 codes in lowercase,
bra for Brazil or usa for the United States; the full list is in
word-map-index.json.
Write the names in lowercase: the map stores every short name in lowercase and finds lands with a case-sensitive
match, so BRA paints nothing.
Lands with no value keep the Fill of the map. The map is updated when a Value changes or when Lands is replaced:
this sample sets random values every half second, and the ToggleBrazil command of its view model (no button calls
it in the sample views) replaces Lands with a copy without Brazil, and back.

<UserControl x:Class="WinUISample.Maps.World.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Maps.World"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:GeoMap
x:Name="geoMap"
Series="{Binding Series}"
MapProjection="Mercator">
</lvc:GeoMap>
</UserControl>
using System;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore.Geo;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
namespace ViewModelsSamples.Maps.World;
public partial class ViewModel
{
private bool _isBrazilInChart = true;
private readonly HeatLand _brazil;
private readonly Random _r = new();
public ViewModel()
{
// every country has a unique identifier
// check the "shortName" property in the following
// json file to assign a value to a country in the heat map
// https://github.com/Live-Charts/LiveCharts2/blob/f904fac8988c4792d2570e8245736e33479e1238/docs/_assets/word-map-index.json
var lands = new HeatLand[]
{
new() { Name = "bra", Value = 13 },
new() { Name = "mex", Value = 10 },
new() { Name = "usa", Value = 15 },
new() { Name = "can", Value = 8 },
new() { Name = "ind", Value = 12 },
new() { Name = "deu", Value = 13 },
new() { Name= "jpn", Value = 15 },
new() { Name = "chn", Value = 14 },
new() { Name = "rus", Value = 11 },
new() { Name = "fra", Value = 8 },
new() { Name = "esp", Value = 7 },
new() { Name = "kor", Value = 10 },
new() { Name = "zaf", Value = 12 },
new() { Name = "are", Value = 13 }
};
Series = [new HeatLandSeries { Lands = lands }];
_brazil = lands.First(x => x.Name == "bra");
DoRandomChanges();
}
public HeatLandSeries[] Series { get; set; }
[RelayCommand]
public void ToggleBrazil()
{
var lands = Series[0].Lands;
if (lands is null) return;
if (_isBrazilInChart)
{
Series[0].Lands = lands.Where(x => x != _brazil).ToArray();
_isBrazilInChart = false;
return;
}
Series[0].Lands = [.. lands, _brazil];
_isBrazilInChart = true;
}
private async void DoRandomChanges()
{
await Task.Delay(1000);
while (true)
{
foreach (var shape in Series[0].Lands ?? Enumerable.Empty<IWeigthedMapLand>())
{
shape.Value = _r.Next(0, 20);
}
await Task.Delay(500);
}
}
}
This sample uses the Mercator projection, see map projections.
A map draws the borders of the GeoJSON file it is given. Some borders are disputed (Crimea, Taiwan, Western Sahara, Kashmir and others) and no single file satisfies every audience. If the borders of the built-in map do not match what you need, load another file, see custom maps.
Heat map colors
HeatMap is an array of LvcColor, it needs at
least two colors. The first color is used for the lowest value (the "coldest") and the last one for the highest (the
"hottest"), any value in between gets a color interpolated linearly between them. When it is not set, the gradient
goes from light blue to dark blue.

using SkiaSharp;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Series = new HeatLandSeries[]
{
new HeatLandSeries
{
HeatMap = new[] // mark
{ // mark
SKColors.LightPink.AsLvcColor(), // the first element is the "coldest" // mark
SKColors.Pink.AsLvcColor(), // mark
SKColors.DeepPink.AsLvcColor() // the last element is the "hottest" // mark
}, // mark
Lands = new HeatLand[]
{
new HeatLand { Name = "bra", Value = 13 },
new HeatLand { Name = "mex", Value = 10 },
new HeatLand { Name = "usa", Value = 15 },
new HeatLand { Name = "deu", Value = 13 },
new HeatLand { Name = "fra", Value = 8 },
new HeatLand { Name = "kor", Value = 10 },
new HeatLand { Name = "zaf", Value = 12 },
new HeatLand { Name = "are", Value = 13 }
}
}
};
By default the gradient goes from the lowest to the highest value in Lands. Set MinValue and MaxValue to fix
that range, for example to keep the same colors while the data changes; values outside the range take the first or
the last color. The heat legend shows the same range.
ColorStops sets where each color of the HeatMap is placed in the gradient, from 0 to 1, with one item for each
color. It works as in the heat series, see
color stops.
Stroke and fill
Stroke and Fill are properties of the map, not of the series. Stroke draws the border of every land, white by
default. Fill paints the lands that have no value in any series, light gray by default; the lands with a value keep
their heat color.
public SolidColorPaint Stroke { get; set; } =
new SolidColorPaint(SKColors.Red) { StrokeThickness = 2 }; // mark
<lvc:GeoMap
Series="{Binding Series}"
Stroke="{Binding Stroke}"> <!-- mark -->
</lvc:GeoMap>

public SolidColorPaint Fill { get; set; } = new SolidColorPaint(SKColors.LightPink); // mark
<lvc:GeoMap
Series="{Binding Series}"
Fill="{Binding Fill}"> <!-- mark -->
</lvc:GeoMap>

On the orthographic projection, Fill also paints the disc of the globe.
Paints can also draw gradients and dashed lines, see the Paints article.
Map projections
MapProjection sets how longitudes and latitudes are placed on the screen. The map keeps the aspect ratio of the
projection and is centered in the control.
| Value | Result |
|---|---|
Default |
The default. Longitude and latitude are used as X and Y directly (an equirectangular map). |
Mercator |
The projection of most web maps; it keeps the shapes and stretches the areas near the poles. |
Orthographic |
A globe: only the hemisphere that faces the viewer is drawn, lands are cut at the horizon. |
<lvc:GeoMap
Series="{Binding Series}"
MapProjection="Mercator"> <!-- mark -->
</lvc:GeoMap>
The basic map uses Mercator. This is the same data with the Default projection:

And with Orthographic, which faces longitude 0 and latitude 0 until you rotate it, see
rotate the globe:

Map bounds
MinLatitude, MaxLatitude, MinLongitude and MaxLongitude crop the map to a region, in degrees. They are
double.NaN by default, which keeps the default of the projection: Mercator goes from latitude -65 to 85, which
leaves out the empty band around Antarctica and keeps Greenland, and Default shows the whole earth. Set
MinLatitude to -85 to show Antarctica on a Mercator map.
Set the four bounds to focus on a region. These bounds frame Europe, from Iceland to the Caucasus and from the coast of North Africa to the North Cape:
<lvc:GeoMap
Series="{Binding Series}"
MapProjection="Mercator"
MinLatitude="35"
MaxLatitude="72"
MinLongitude="-25"
MaxLongitude="45"> <!-- mark -->
</lvc:GeoMap>

The same bounds work with the Default projection, without the stretching of Mercator:

The orthographic projection ignores the bounds, rotate the globe instead.
Rotate the globe
On the orthographic projection, CenterLongitude and CenterLatitude of the CoreChart set the point the globe
faces. Setting them turns the globe at once; RotateTo(longitude, latitude, durationMs) animates the rotation, in
800 ms by default, and takes the shortest way around the globe. The other projections do not use these properties.
// faces Europe and Africa at once
geoMap.CoreChart.CenterLongitude = 15; // mark
geoMap.CoreChart.CenterLatitude = 20; // mark
// rotates to Tokyo
geoMap.CoreChart.RotateTo(longitude: 139.69, latitude: 35.69); // mark

The rotating orthographic sample calls RotateTo every 5 seconds, from North America (-95, 35) to Asia
(100, 35) and back. The view starts the loop when it is loaded, with
vm.Start((lon, lat) => geoMap.CoreChart.RotateTo(lon, lat)), and stops it when it is unloaded; the view model posts
each call to the UI thread:

<UserControl x:Class="WinUISample.Maps.RotatingOrthographic.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Maps.RotatingOrthographic"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:GeoMap x:Name="geoMap"
Series="{Binding Series}"
MapProjection="Orthographic"/>
</UserControl>
using System;
using System.Threading;
using System.Threading.Tasks;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
namespace ViewModelsSamples.Maps.RotatingOrthographic;
public class ViewModel
{
private static readonly (double Lon, double Lat)[] s_path =
[
(-95, 35), // North America
(100, 35) // Asia
];
private CancellationTokenSource? _cts;
private SynchronizationContext? _ctx;
public ViewModel()
{
var lands = new HeatLand[]
{
new() { Name = "bra", Value = 13 },
new() { Name = "mex", Value = 10 },
new() { Name = "usa", Value = 15 },
new() { Name = "can", Value = 8 },
new() { Name = "ind", Value = 12 },
new() { Name = "deu", Value = 13 },
new() { Name = "jpn", Value = 15 },
new() { Name = "chn", Value = 14 },
new() { Name = "rus", Value = 11 },
new() { Name = "fra", Value = 8 },
new() { Name = "esp", Value = 7 },
new() { Name = "kor", Value = 10 },
new() { Name = "zaf", Value = 12 },
new() { Name = "are", Value = 13 },
new() { Name = "aus", Value = 9 },
new() { Name = "arg", Value = 6 },
new() { Name = "egy", Value = 7 },
new() { Name = "nga", Value = 11 },
new() { Name = "gbr", Value = 9 }
};
Series = [new HeatLandSeries { Lands = lands }];
}
public HeatLandSeries[] Series { get; set; }
// Starts the infinite rotation loop. Call from the UI thread so we can
// capture its SynchronizationContext and dispatch RotateTo back to it —
// saves every platform view from writing its own Dispatcher.Invoke.
public void Start(Action<double, double> rotate)
{
Stop();
_ctx = SynchronizationContext.Current;
_cts = new CancellationTokenSource();
_ = RunAsync(rotate, _cts.Token);
}
public void Stop()
{
_cts?.Cancel();
_cts = null;
}
private async Task RunAsync(Action<double, double> rotate, CancellationToken ct)
{
var i = 0;
while (!ct.IsCancellationRequested)
{
var (lon, lat) = s_path[i];
Dispatch(() => rotate(lon, lat));
try { await Task.Delay(TimeSpan.FromSeconds(5), ct); }
catch (OperationCanceledException) { return; }
i = (i + 1) % s_path.Length;
}
}
private void Dispatch(Action action)
{
if (_ctx is null) action();
else _ctx.Post(_ => action(), null);
}
}
Custom maps
ActiveMap is the map the control draws, the built-in world map by default. Load your own GeoJSON file with
Maps.GetMapFromDirectory(path) or Maps.GetMapFromStreamReader(reader), from the LiveChartsCore.Geo namespace,
and assign the result to ActiveMap. DrawnMap.GetMapFromDirectoryAsync(path) and
DrawnMap.GetMapFromStreamReaderAsync(reader) load the file on another thread.
The map reads the Polygon and MultiPolygon features of the file, other geometry types are skipped. Each feature
needs a name property, shown in the tooltip, and should have a shortName property, the name the series use; when
shortName is missing, the name is used instead. Both are read in lowercase.
This sample loads the states of Mexico from a file embedded in the assembly, gives a value to each state, and crops the map with the map bounds:

<UserControl x:Class="WinUISample.Maps.CustomMap.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Maps.CustomMap"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:GeoMap
x:Name="geoMap"
Series="{Binding Series}"
ActiveMap="{Binding ActiveMap}"
MapProjection="Mercator"
MinLatitude="13"
MaxLatitude="33"
MinLongitude="-120"
MaxLongitude="-85"/>
</UserControl>
using System;
using System.IO;
using System.Reflection;
using LiveChartsCore.Geo;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
namespace ViewModelsSamples.Maps.CustomMap;
public class ViewModel
{
public ViewModel()
{
// Load a custom GeoJSON as the chart's ActiveMap. Here it's an
// embedded resource shipped with the sample, but Maps also exposes
// GetMapFromDirectory(string path) for files on disk and a
// DrawnMap(StreamReader, layerName) constructor for any IO source.
//
// The mexico-states.geojson file ships under
// samples/ViewModelsSamples/Maps/CustomMap/ and is registered as an
// <EmbeddedResource> in ViewModelsSamples.csproj.
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("ViewModelsSamples.Maps.CustomMap.mexico-states.geojson")
?? throw new InvalidOperationException(
"Embedded resource mexico-states.geojson was not found — make sure the build copied it.");
using var reader = new StreamReader(stream);
ActiveMap = LiveChartsCore.Geo.Maps.GetMapFromStreamReader(reader);
// Synthetic values per state — the shortName in mexico-states.geojson
// is the ISO 3166-2 region code without the 'mx-' prefix, lowercased.
// Replace these with population / GDP / your own metric.
Series =
[
new HeatLandSeries
{
Name = "Population (synthetic)",
Lands =
[
new HeatLand { Name = "agu", Value = 13 }, // Aguascalientes
new HeatLand { Name = "bcn", Value = 36 }, // Baja California
new HeatLand { Name = "bcs", Value = 8 }, // Baja California Sur
new HeatLand { Name = "cam", Value = 10 }, // Campeche
new HeatLand { Name = "chp", Value = 56 }, // Chiapas
new HeatLand { Name = "chh", Value = 38 }, // Chihuahua
new HeatLand { Name = "cmx", Value = 92 }, // Ciudad de México
new HeatLand { Name = "coa", Value = 32 }, // Coahuila
new HeatLand { Name = "col", Value = 7 }, // Colima
new HeatLand { Name = "dur", Value = 18 }, // Durango
new HeatLand { Name = "gua", Value = 62 }, // Guanajuato
new HeatLand { Name = "gro", Value = 35 }, // Guerrero
new HeatLand { Name = "hid", Value = 31 }, // Hidalgo
new HeatLand { Name = "jal", Value = 84 }, // Jalisco
new HeatLand { Name = "mex", Value = 170 }, // México (state)
new HeatLand { Name = "mic", Value = 47 }, // Michoacán
new HeatLand { Name = "mor", Value = 19 }, // Morelos
new HeatLand { Name = "nay", Value = 12 }, // Nayarit
new HeatLand { Name = "nle", Value = 58 }, // Nuevo León
new HeatLand { Name = "oax", Value = 41 }, // Oaxaca
new HeatLand { Name = "pue", Value = 65 }, // Puebla
new HeatLand { Name = "que", Value = 23 }, // Querétaro
new HeatLand { Name = "roo", Value = 18 }, // Quintana Roo
new HeatLand { Name = "slp", Value = 28 }, // San Luis Potosí
new HeatLand { Name = "sin", Value = 30 }, // Sinaloa
new HeatLand { Name = "son", Value = 29 }, // Sonora
new HeatLand { Name = "tab", Value = 24 }, // Tabasco
new HeatLand { Name = "tam", Value = 35 }, // Tamaulipas
new HeatLand { Name = "tla", Value = 13 }, // Tlaxcala
new HeatLand { Name = "ver", Value = 80 }, // Veracruz
new HeatLand { Name = "yuc", Value = 23 }, // Yucatán
new HeatLand { Name = "zac", Value = 15 }, // Zacatecas
],
},
];
}
public DrawnMap ActiveMap { get; }
public HeatLandSeries[] Series { get; }
}
Markers on the map
The map draws its VisualElements on top of the lands, as the other charts do. Wrap a
Visual in a GeoVisualElement and set its
Longitude and Latitude to pin it to a place: the map moves the visual to that place on every update, so it
follows the zoom, the pan and the rotation of the globe. When the place is on the hidden side of the globe, the visual
is not drawn.
In this sample, CityMarkerVisual draws a circle, and a GeoVisualElement places one at each city. The visual must
not set the position of its drawn element in Measure, because that is where the map writes the projected position;
the TranslateTransform centers the circle on that point.
VisualElements is not a bindable property of the map, so the view sets it in the code behind.

<UserControl x:Class="WinUISample.Maps.MarkersOnMap.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Maps.MarkersOnMap"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<!-- VisualElements is wired up in code-behind because the GeoMap source-gen
doesn't currently expose it as a bindable property. -->
<lvc:GeoMap
x:Name="geoMap"
Series="{Binding Series}"
MapProjection="Mercator"/>
</UserControl>
using LiveChartsCore.Geo;
using LiveChartsCore.Kernel;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
namespace ViewModelsSamples.Maps.MarkersOnMap;
public class ViewModel
{
public ViewModel()
{
// A handful of cities scattered across hemispheres so the markers
// visibly track pan / zoom / orthographic rotation.
VisualElements =
[
CityMarker(longitude: -74.00, latitude: 40.71), // New York
CityMarker(longitude: 139.69, latitude: 35.69), // Tokyo
CityMarker(longitude: -3.70, latitude: 40.42), // Madrid
CityMarker(longitude: -46.63, latitude: -23.55), // São Paulo
CityMarker(longitude: 151.21, latitude: -33.87), // Sydney
];
}
public HeatLandSeries[] Series { get; } =
[
new HeatLandSeries
{
Lands =
[
new HeatLand { Name = "usa", Value = 15 },
new HeatLand { Name = "jpn", Value = 14 },
new HeatLand { Name = "esp", Value = 10 },
new HeatLand { Name = "bra", Value = 12 },
new HeatLand { Name = "aus", Value = 11 },
],
},
];
public IChartElement[] VisualElements { get; }
private static GeoVisualElement CityMarker(double longitude, double latitude) =>
// GeoVisualElement wraps a visual and re-projects its (Longitude, Latitude)
// to screen pixels each Measure pass. The inner visual then draws at that
// pixel — pan / zoom / orthographic rotation all follow automatically.
new(new CityMarkerVisual())
{
Longitude = longitude,
Latitude = latitude,
};
}
using LiveChartsCore;
using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.VisualElements;
using SkiaSharp;
namespace ViewModelsSamples.Maps.MarkersOnMap;
public class CityMarkerVisual : Visual
{
private const float Size = 14f;
// GeoVisualElement writes the projected pixel onto this geometry, so do not set X or Y
// in Measure below or the marker would ignore the coordinate it is anchored to.
//
// The translate centers the circle on the projected point; without it the geometry's
// top-left corner would sit on the coordinate.
//
// Declared as IDrawnElement rather than CircleGeometry: net462 does not support covariant
// returns, and Measure has no need for the derived type here.
protected override IDrawnElement DrawnElement { get; } = new CircleGeometry
{
Width = Size,
Height = Size,
Fill = new SolidColorPaint(new SKColor(255, 87, 51)), // OrangeRed
Stroke = new SolidColorPaint(SKColors.White),
// A geometry that carries its own paints is drawn with the thickness set here, the one on
// the paint is ignored, so setting it there would silently draw a 1px hairline instead.
StrokeThickness = 2,
TranslateTransform = new(-Size / 2f, -Size / 2f),
};
protected override void Measure(Chart chart)
{ }
}
To place or hit-test something yourself, geoMap.CoreChart.Project(longitude, latitude) returns the pixel of a
coordinate, or null when the coordinate is on the hidden side of the globe. geoMap.CoreChart.Unproject(point)
returns the coordinate of a pixel, or null when the pixel is outside the disc of the globe.
var coordinate = geoMap.CoreChart.Unproject(new LvcPoint(x, y));
if (coordinate is null) return; // the pixel is outside the globe
var (longitude, latitude) = coordinate.Value;
Zooming and panning
InteractionMode enables the zoom and the pan, it is None by default. It is a flag enum:
| Value | Wheel zoom | Drag to pan |
|---|---|---|
None |
no | no |
Pan |
no | yes |
Zoom |
yes | no |
Both |
yes | yes |
<lvc:GeoMap
Series="{Binding Series}"
InteractionMode="Both"> <!-- mark -->
</lvc:GeoMap>
The wheel zooms around the pointer. ZoomingSpeed sets how much each step of the wheel zooms, from 0.1 to 0.95,
0.2 by default. The zoom level goes from MinZoomLevel (1 by default) to MaxZoomLevel (100). When the user
releases the pointer, the map springs back to cover the control: it undoes a zoom below MinZoomLevel and a pan that
leaves an empty band at an edge. Dragging an orthographic map moves the globe, it does not rotate it.
From code, the CoreChart of the map has ZoomLevel to read or set the zoom, Zoom(pivot, direction) to zoom around
a pixel, Pan(delta) to move the map by a number of pixels, and ResetViewport() to go back to zoom 1 with no pan.
They work whatever the InteractionMode.
Title and legend
Title draws a visual above the map, and the map leaves room for it. A DrawnLabelVisual draws a text; when its paint
is not set, the theme picks it. For a heat map, set Legend to an SKHeatLegend and LegendPosition to a side,
LegendPosition is Hidden by default. The legend draws the HeatMap of the first series as a gradient, with the
lowest and highest values at its ends; set IsVisibleAtLegend to false on a series to skip it.
geoMap.Title = new DrawnLabelVisual(
new LabelGeometry
{
Text = "World population by country",
TextSize = 20,
Padding = new LiveChartsCore.Drawing.Padding(12)
});
geoMap.LegendPosition = LiveChartsCore.Measure.LegendPosition.Right;
geoMap.Legend = new SKHeatLegend();

These are plain properties of the map, not bindable ones: set them in the code behind, or declare them inside the
control, where the draw prefix maps to the LiveChartsCore.SkiaSharpView.SKCharts namespace:
<lvc:GeoMap
Series="{Binding Series}"
LegendPosition="Right">
<lvc:GeoMap.Title>
<lvc:XamlDrawnLabelVisual Text="World population by country" TextSize="20"/>
</lvc:GeoMap.Title>
<lvc:GeoMap.Legend>
<draw:SKHeatLegend/>
</lvc:GeoMap.Legend>
</lvc:GeoMap>
The map does not redraw when Title, Legend or LegendPosition change; set them before the map is shown, or call
geoMap.CoreChart.Update() after changing them. LegendTextSize and LegendBackgroundPaint style the legend, see
the legends article.
Tooltips
The tooltip opens when the pointer is over a land. It shows the name of the land and one line per series that has a
value for it, in the order of the Series collection; each line is Name: Value with two decimals, or only the
value when the series has no Name.
TooltipPosition places it relative to the center of the land:
| Value | Placement |
|---|---|
Auto |
The default. Above the land, or below it when there is no room above. |
Top |
Always above the land. |
Bottom |
Always below the land. |
Hidden |
No tooltip. |
TooltipTextSize (14 by default), TooltipTextPaint and TooltipBackgroundPaint style the default tooltip, as in
the tooltips article.
TooltipFormatter replaces the text of each value line; it takes a GeoTooltipValue, with the Series and the
Value. Like the title, it is a plain property of the map, set it from code:
geoMap.TooltipFormatter = v => $"{v.Series.Name}: {v.Value:C0}"; // mark
For a different layout, inherit from SKDefaultGeoTooltip and override GetLayout(), or implement IGeoMapTooltip
(its Show() and Hide() methods) from scratch, and assign it to the Tooltip property of the map.
public class MyTooltip : SKDefaultGeoTooltip
{
protected override Layout<SkiaSharpDrawingContext> GetLayout(
GeoTooltipPoint point, GeoMapChart chart, Theme theme, PopUpPlacement placement)
{
// build your own layout here
return base.GetLayout(point, chart, theme, placement);
}
}
geoMap.Tooltip = new MyTooltip();
Pointer events
DataPointerDown fires when the user clicks a land (a press and release that moves the pointer less than 5 pixels),
and HoveredPointsChanged fires when the pointer enters a land, moves to another one or leaves it. Each ChartPoint
in these events has the land as its Context.DataSource, a
LandDefinition with the Name and ShortName
of the land, and TryGetValue on a series returns its value for that land:
using System.Linq;
using LiveChartsCore.Geo;
geoMap.DataPointerDown += (sender, points) =>
{
if (points.FirstOrDefault()?.Context.DataSource is not LandDefinition land) return;
foreach (var series in geoMap.Series ?? [])
if (series.TryGetValue(land.ShortName, out var value))
Console.WriteLine($"{land.Name}, {series.Name}: {value}");
};
geoMap.GetPointsAt(new LvcPointD(x, y)) returns the land at a pixel in the same form, without an event.
Series, names and updates
Landstakes anyICollection<HeatLand>.HeatLandnotifies when itsValuechanges and the map is updated; replacingLands, or adding and removing items of anObservableCollection, updates it too, see automatic updates.- To use your own type instead of
HeatLand, implementIWeigthedMapLandand useHeatLandSeries<TModel>. Name(set it in code, the series has no XAML version) is shown in the tooltip.- A map can have several series. When two series give a value to the same land, the land takes the color of the last one, and the tooltip shows both values.